﻿using StevensReceipts.Domain;
using StevensReceipts.Repository;

namespace StevensReceipts.Repository
{
    public class ReceiptsDataSource : IReceiptsDataSource
    {
        #region Implementation of IUOW

        readonly ReceiptsDbContext _context = new ReceiptsDbContext();

        private IRepository<Address> _addresses;

        private IRepository<ChartofAccount> _chartofAccounts;

        private IRepository<ChartofAccountAccountType> _chartofAccountAccountTypes;

        private IRepository<ChartofAccountCategory> _coaCategories;

        private IRepository<Contact> _contacts;

        private IRepository<Receipt> _receipts;

        private IRepository<TaxRate> _taxRates;

        private IRepository<ReceiptItem> _receiptItems;

        private IRepository<Invoice> _invoices;

        private IRepository<UserProfile> _userProfiles;

        private IRepository<UserPermissionLine> _userPermissions;
 
        public IRepository<UserPermissionLine> UserPermissions
        {
            get { return _userPermissions ?? (_userPermissions = new Repository<UserPermissionLine>(_context)); }
        }

        public IRepository<UserProfile> UserProfiles
        {
            get { return _userProfiles ?? (_userProfiles = new Repository<UserProfile>(_context)); }
        } 

        public IRepository<Invoice> Invoices
        {
            get { return _invoices ?? (_invoices = new Repository<Invoice>(_context)); }
        } 
 
        public IRepository<ReceiptItem> ReceiptItems
        {
            get { return _receiptItems ?? (_receiptItems = new Repository<ReceiptItem>(_context)); }
        } 

        public IRepository<Address> Addresses { 
            get { return _addresses ?? (_addresses = new Repository<Address>(_context)); }
        }

        private IRepository<Business> _businesses; 
        public IRepository<Business> Businesses { 
            get { return _businesses ?? (_businesses = new Repository<Business>(_context)); }
        }

        public IRepository<ChartofAccount> ChartofAccounts
        {
            get { return _chartofAccounts ?? (_chartofAccounts = new Repository<ChartofAccount>(_context)); }
        }

        public IRepository<ChartofAccountAccountType> ChartofAccountAccountTypes
        {
            get { return _chartofAccountAccountTypes ?? (_chartofAccountAccountTypes = new Repository<ChartofAccountAccountType>(_context)); }
        }

        public IRepository<ChartofAccountCategory> CoaCategories
        {
            get { return _coaCategories ?? (_coaCategories = new Repository<ChartofAccountCategory>(_context)); }
        }

        public IRepository<Contact> Contacts
        {
            get { return _contacts ?? (_contacts = new Repository<Contact>(_context)); }
        }

        public IRepository<Receipt> Receipts
        {
            get { return _receipts ?? (_receipts = new Repository<Receipt>(_context)); }
        }

        public IRepository<TaxRate> TaxRates
        {
            get { return _taxRates ?? (_taxRates = new Repository<TaxRate>(_context)); }
        }

        private IRepository<Client> _clients;
        public IRepository<Client> Clients
        {
            get { return _clients ?? (_clients = new Repository<Client>(_context)); }
        } 

        public void Save()
        {
            _context.SaveChanges();
        }

        #endregion
    }
}